package com.gp.dal.main;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.gp.dal.util.MybatisUtil;
import com.gp.dal.mapper.UserMapper;
import com.gp.dal.model.SexEnum;
import com.gp.dal.model.User;


/**
 * Created by Zhanggd on 2017/7/1.
 */
public class UserMapperTest {

	private static final SqlSessionFactory SQLSESSIO_FACTORY = MybatisUtil.getInstance();
	
    public static void main(String[] args) {
    	add();
    }
    
    public static void add(){
    	SqlSession session = SQLSESSIO_FACTORY.openSession();
    	@SuppressWarnings("unchecked")
		UserMapper<User> userMapper = session.getMapper(UserMapper.class);
    	User user = new User();
    	user.setId(2);
    	user.setName("gupao");
    	SexEnum sexEnum = SexEnum.MAN;
    	user.setSex(sexEnum);
    	try {
			user.setBirs(new SimpleDateFormat("yyyy-MM-dd").parse("1995-01-01"));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	user.setMessage("This is Clob!");
    	
    	userMapper.add(user);
    	session.commit();
    }
}
